<?php
$this->breadcrumbs=array(
	'活動管理'=>array('index'),
	'活動詳情',
);
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/css/styles.css');
?>
<style>
td {
	border: solid #68BADA;
	border-width: 0px 1px 1px 0px;
	padding: 5px;
	text-align: center
}
table {
	border: solid #68BADA;
	border-width: 1px 0px 0px 1px;
}
.odd {
	background: none repeat scroll 0 0 #EEEEEE;
}
.even {
	background: none repeat scroll 0 0 #FFFFFF;
}
.three {
	background: none repeat scroll 0 0 #E5F1F4;
}
.jg {
	background: none repeat scroll 0 0 #ADD9ED;
}
.head {
	background: none repeat scroll 0 0 #90D8F0;
}
input, img {
	vertical-align: middle;
}
</style>
<script>
function unwin(code,id){
	if(!confirm('確認要取消中獎:'+code)){
		return false;
	}
	$.post('/admin/index.php?r=activity/unwin',{'id':id}, function (data) {
        var ret = $.parseJSON(data);
        if (ret != null && ret.success != null && ret.success) {
			alert(ret.msg);
			location.reload(true);
        }
	});	
}
function win(code,id){
	if(!confirm('確認要設置為中獎:'+code)){
		return false;
	}
	$.post('/admin/index.php?r=activity/win',{'id':id}, function (data) {
        var ret = $.parseJSON(data);
        if (ret != null && ret.success != null && ret.success) {
			alert(ret.msg);
			location.reload(true);
        }
	});	
}
</script>
<table class="detail-view">
	<tbody>
		<tr class="odd">
			<td width="16%">ID</td>
			<td width="34%">
				<?= $model->serial ?>
			</td>
			<td width="16%">名稱</td>
			<td>
				<?= $model->activityname ?>
			</td>
		</tr>
		<tr class="even">
			<td>分類</td>
			<td>
				<?= $model->class ?>
			</td>
			<td>開始時間</td>
			<td>
				<?= $model->starttime ?>
			</td>
		</tr>		
		<tr class="odd">
            <td>是否推薦</td>
            <td><?=Yii::app()->params['activityrecommend'][$model->recommend]?></td>
            <td>狀態</td>
            <td><?=Yii::app()->params['activitystatus'][$model->status]?></td>
        </tr>		
		<tr class="even">
			<td>參加人數</td>
			<td>
				<?= $model->people ?>
			</td>
			<td>中獎人數</td>
			<td>
				<?= $model->winner ?>
			</td>
		</tr>
		<tr class="odd">
            <td>參加次數</td>
            <td><?= $model->times ?></td>
            <td>通關密語</td>
            <td><?= $model->code ?></td>
        </tr>
		<tr class="even">
			<td>通關密語等待時間</td>
			<td>
				<?= $model->code_time ?>
			</td>
			<td>影片鏈接</td>
			<td>
				<?= $model->movie_url ?>
			</td>
		</tr>
		<tr class="odd">
            <td>遊戲鏈接</td>
            <td><?= $model->game_url ?></td>
            <td>問卷鏈接</td>
            <td><?= $model->poll_url ?></td>
        </tr>
		<tr class="even">
			<td>結束時間</td>
			<td>
				<?= $model->endtime ?>
			</td>
			<td>開獎延時</td>
			<td>
				<?= $model->delaytime ?>
			</td>
		</tr>
		<tr class="odd">
            <td>創建時間</td>
            <td><?= $model->dateline ?></td>
            <td>更新時間</td>
            <td><?= $model->updated ?></td>
        </tr>
	</tbody>
</table>
<br /><br />
<div style="width:100%; float:left; margin-bottom:10px; text-align:right;">
	<form action="<?=Yii::app()->createUrl('activity/view')?>" name="jobForm" id="jobForm" method="get">		
		參與者: <input type="text" name="username" value="<?php if(isset($search['username']))echo $search['username'];?>" id="username" size="20" />&nbsp;&nbsp;
		抽獎號碼: <input type="text" name="code" value="<?php if(isset($search['code']))echo $search['code'];?>" id="code" size="20" />&nbsp;&nbsp;
		<input type="image" src="images/go.png" id="jobSub" />
		<input type="hidden" name="r" value="activity/view" />
		<input type="hidden" name="id" value="<?= $model->activityid ?>" />
	</form>
</div>
<table cellspacing="0" cellpadding="0" width="100%" class="tbl">
	<tr class="head">
		<td align="center" width="30%" height="20">抽獎號碼</td>
		<td align="center" width="30%">參與者</td>
		<td align="center" width="20%">狀態</td>
		<td align="center">操作</td>
	</tr>
	<?php
    $i = 0;
    $cssArr = array(0 => 'even', 1 => 'odd', 2 => 'three');
    foreach ($rowTable as $item) {
        $trClass = $cssArr[$i % 3];
        $i++;
    ?>
	<tr class="<?= $trClass ?>" <?php if($item->win==1){?> style="color:red;"<?php }?>>
		<td>
			<?=$item->code?>
		</td>
		<td>
			<?=$item->user->username?>
		</td>
		<td>
			<?=Yii::app()->params['recordstatus'][$item->win]?>
		</td>
		<td>
		<?php
		if($item->win==0){
		?>
		<a href="###" onclick="win('<?=$item->code?>',<?=$item->rid?>)">設置為中獎</a>
		<?	
		}else{
		?>
		<a href="###" onclick="unwin('<?=$item->code?>',<?=$item->rid?>)">取消中獎</a>
		<?
		}
		?>
		</td>	
	</tr>
	<?php
    }
    ?>
</table>
<div id="pager" align="center" style=" margin:10px 0;">
	<?php  
	$this->widget('CLinkPager',array(  
		'header'=>'',  
		'firstPageLabel' => '<<',
		'lastPageLabel' => '>>',
		'prevPageLabel' => '<',
		'nextPageLabel' => '>',
		'pages' => $pages,  
		'maxButtonCount'=>13  
		));  
?>
</div>